﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                 { display: '编号', name: 'ID', width: "5%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '审核状态', name: 'Status', hide: true },
                    { display: '企业名称', name: 'EnterpriseName', width: "25%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '借款金额', name: 'BorrowAmount', width: "15%", sortable: false, align: 'left' },
                    { display: '借款期限(月)', name: 'LoanPeriod', width: "15%", sortable: false, align: 'left' },
                    { display: '联系方式', name: 'Tel', width: "12%", sortable: false, align: 'left' },
                    //{ display: '注册资金', name: 'RegistedCapital', width: "8%", sortable: false, align: 'left' },
                    { display: '企业概况', name: 'Remarks', width: "15%", sortable: false, align: 'left' },
                    { display: '操作', name: 'ID', width: "25%", sortable: false, align: 'center', process: processOp }
                    //{ display: '编号', name: 'ID', width: "5%", sortable: true, hide: false, align: 'left', iskey: true },
                    //{ display: '状态', name: 'Status', hide:true, sortable: false, align: 'left'},
                    //{ display: '企业名称', name: 'EnterpriseName', width: "15%", sortable: true, hide: false, align: 'left', iskey: true },
                    //{ display: '行业', name: 'Trade', width: "15%", sortable: false, align: 'left' },
                    //{ display: '注册日期', name: 'RegistedDate', width: "12%", sortable: false, align: 'left' },
                    ////{ display: '注册资金', name: 'RegistedCapital', width: "8%", sortable: false, align: 'left' },
                    //{ display: '经营情况', name: 'BusinessCircumstance', width: "15%", sortable: false, align: 'left' },
                    //{ display: '操作', name: 'ID', width: "15%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "ID",
            sortorder: "ASC",
            title: false,
            rp: 10,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[1] == 0) {
                ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            } else if (cell[1] == 1 || cell[1]==2) {
                ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
                ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            window.location.href = url;
        });

        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };
        util.See = function (id, name) {
            var url = options.ShowUrl + "/" + id;
            location.href = url;
            }
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert(res.Message);
                          xjgrid.Reload(this);
                      }
                      else {
                          alert(res.Message);
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);